<template>
  <div class="app-container">
    <div class="headerWarp">
      <div class="grid-content bg-purple">
        <span>卡片来源:</span>
        <el-select v-model="listQuery.cardSource" clearable placeholder="请选择卡片来源">
          <el-option
            v-for="item in options1"
            :key="item.options1"
            :label="item.cardSource"
            :value="item.cardSource"
          />
        </el-select>
      </div>
      <div class="grid-content bg-purple">
        <span>客户:</span>
        <el-select v-model="listQuery.staffId" clearable placeholder="请选择用户">
          <el-option
            v-for="item in options2"
            :key="item.staffId"
            :label="item.staffName"
            :value="item.staffId"
          />
        </el-select>
      </div>
      <div class="grid-content bg-purple">
        <span>ICCID:</span>
        <el-input v-model.trim="listQuery.iccidCode" placeholder="请输入iccid码" clearable @keyup.enter.native="handleSearch" />
      </div>
      <div class="grid-content bg-purple">
        <span>用户码:</span>
        <el-input v-model.trim="listQuery.userCode" placeholder="请输入用户码" clearable @keyup.enter.native="handleSearch" />
      </div>
      <div class="actionHeader">
        <el-button style="margin:0 0 20px 20px;" type="primary" icon="el-icon-document" @click="handleSearch">
          查询
        </el-button>
      </div>
      <div class="actionHeader">
        <el-button style="margin:0 0 20px 20px;" type="danger" icon="el-icon-info" @click="resetAlldata">
          重置
        </el-button>
      </div>
      <el-button style="margin-left:20px;" type="default">卡总数：<span style="color:#333">{{ total }}条</span></el-button>
    </div>

    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :default-sort="{prop:'userCode',order:'descending'}"
      highlight-current-row
    >
      <el-table-column align="center" type="index" :index="indexMethods" label="序号" width="80" />
      <el-table-column label="用户码" prop="userCode" sortable align="center">
        <template slot-scope="scope">
          {{ scope.row.userCode }}
        </template>
      </el-table-column>

      <el-table-column label="ICCID" align="center">
        <template slot-scope="scope">
          {{ scope.row.iccidCode }}
        </template>
      </el-table-column>
      <el-table-column label="接入码" align="center">
        <template slot-scope="scope">
          {{ scope.row.accessCode }}
        </template>
      </el-table-column>
      <el-table-column label="卡片来源" align="center">
        <template slot-scope="scope">
          {{ scope.row.cardSource }}
        </template>
      </el-table-column>
      <el-table-column label="入库时间" align="center">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>  {{ scope.row.stockInTime }}</span></template>
      </el-table-column>
      <el-table-column label="出库时间" prop="stockOutTime" align="center">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span> {{ scope.row.stockOutTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户名称" align="center">
        <template slot-scope="scope">
          {{ scope.row.agentStaff }}
        </template>
      </el-table-column>
    </el-table>

    <div class="pageGation">
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
    </div>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import { getProductlist, getCardSource } from '@/api/productlist'
import { getCustomerSelect } from '@/api/outStorage'
export default {
  components: {
    Pagination
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      json_name: '卡模板下载',
      json_fields: {},
      fileList: [],
      limit: 1,
      dialogFormVisible: false,
      list: [],
      listLoading: true,
      currentPage: 1,
      value: '',
      value1: '未出库',
      options1: [],
      options2: [],
      dialogOut: {
        username: ''
      },
      total: 0, // 总数量
      listQuery: {
        userCode: '',
        iccidCode: '',
        cardSource: '',
        staffId: '',
        pageNo: 1,
        pageSize: 20
      },
      pageInfo: null
    }
  },
  created() {
    this.fetchData()
    this.getSelctAlldata()
    this.getCustomeOption()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      getProductlist(this.listQuery).then(res => {
        if (res.code === '00000') {
          this.listLoading = false
          this.list = res.data.rows
          this.total = res.data.totalRows
        } else {
          this.listLoading = false
        }
      }).catch(err => {
        console.log(err)
      })
    },
    // 自定义序号事件
    indexMethods(index) {
      return (this.listQuery.pageNo - 1) * this.listQuery.pageSize + index + 1
    },
    // 重置
    resetAlldata() {
      this.listQuery.iccidCode = ''
      this.listQuery.cardSource = ''
      this.listQuery.staffId = ''
      this.listQuery.userCode = ''
      this.fetchData()
    },
    // 查询
    handleSearch() {
      this.fetchData()
    },
    // 导入卡数据
    beforeUpload(file) {
      const isLt1M = file.size / 1024 / 1024 < 1
      if (isLt1M) {
        return true
      }
      this.$message({
        message: '请勿上传超过1m的文件',
        type: 'warning'
      })
      return false
    },
    handleSuccess({ results, header }) {
      console.log(results, header)
    },
    // 下拉筛选数据
    getSelctAlldata() {
      getCardSource().then(res => {
        if (res.code === '00000') {
          this.options1 = res.data
        }
      })
    },
    // 下拉代理商
    getCustomeOption() {
      getCustomerSelect().then(res => {
        if (res.code === '00000') {
          this.options2 = res.data
        }
      })
    }
  }
}
</script>
<style scoped lang="scss">
  .headerWarp{
    display: flex;
    justify-content: flex-start;
    align-items: center;
    .grid-content{
      display: flex;
      justify-content:center;
      align-items: center;
      margin-left:15px;
      >span{
        display: block;
        margin: 4px;
        width:70px;
      }
    }
  }
  .actionHeader{
    height:90px;
    line-height:90px;
}
.pageGation{
    display: flex;
    justify-content: flex-end;
    margin: 15px;
    font-size: 23px;
  }
</style>

